<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Subscriber_model extends CI_Model {
  private $table = 'ci_subscribers';
  public function __construct() {
    parent::__construct();
  }

  /**
   * This is required to check if the email is unique.
   * @param $email
   * @return bool
   */
  public function check_for_existing($email) {
    $query = $this->db->select('sid')->from($this->table)->where('email', $email)->get();
    if ($query->num_rows() > 0) {
      return false;
    } else {
      return true;
    }
  }

  /**
   * This function will give me a list of subscribers
   * from the table.
   */
  public function get_subscribers($id = null) {
    $this->db
      ->select('email,created,sid')
      ->from($this->table)
      ->order_by('sid', 'desc');

    if ($id)
      $this->db->where('sid', $id);

    $query = $this->db->get();
    if ($query->num_rows() > 0) {
      return $query->result_array();
    } else {
      return false;
    }
  }
}